package service

import (
	"singo/model"
	"singo/serializer"
	// "github.com/segmentio/ksuid"
	// "github.com/rs/xid"
)

type UserChangeAvatarService struct {
	Avatar string `form:"avatar" json:"avatar" binding:"required"`
}

// ChangeAvatar 用户头像服务
func (service *UserChangeAvatarService) ChangeAvatar(id string) serializer.Response {
	user := model.User{
		Avatar: service.Avatar,
	}

	// 更新用户
	if err := model.DB.Model(&user).Where("uid = ?", id).Updates(&user).Error; err != nil {
		return serializer.ParamErr("更新失败", err)
	}

	return serializer.Response{
		Data:   true,
		Msg:    "成功",
		Status: 0,
	}
}
